package com.example.myjspdemo;

import java.io.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;

@WebServlet(name = "helloServlet", value = "/hello-servlet")
public class HelloServlet extends HttpServlet {
    private String message;

    public void init() {
        message = "这是 Hello Servlet!";
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        // 设置 CORS 响应头
//        response.setHeader("Access-Control-Allow-Origin", "http://localhost:3030");
////        response.setHeader("Access-Control-Allow-Origin", "http://192.168.16.130");
//        response.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
//        response.setHeader("Access-Control-Allow-Headers", "*");
//        response.setHeader("Access-Control-Allow-Credentials", "true");
//        response.setHeader("Access-Control-Max-Age", "3600");

        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
//        out.println("<html><body>");
        out.println("<h1>" + message + "</h1>");// 注意：只返回片段，不是完整HTML
//        out.println("</body></html>");

    }

    public void destroy() {
    }
}